<template>
	<Row>
		<ICol span="24">
			<ReplyItem ref="reply" :callback="getChoiseReply"></ReplyItem>
		</ICol>
		<ICol span="8" offset="8" class="mt-25">
			<Button type="primary" long @click="save">保存</Button>
		</ICol>
	</Row>
</template>
<style>
	.mt-25{margin-top: 15px;}
</style>
<script>
	import {Row,Col,Button} from 'iview';

	import ReplyItem from 'admin/components/wechat/function/reply/reply-item';

	export default {
		components:{
			Row,
            'ICol':Col,
            ReplyItem,
            Button,
		},
		data(){
			return {
				form :{
					type : '',
					replyType : '',
					wechat_text_id : 0,
					wechat_image_id : 0,
					wechat_mpnews_id : 0,
                },
			}
		},
		methods:{
			init(name){
				this.form.type = name;
				this.getData();
			},
			getData(){
				this.Axios.Wechat.Function.Reply.GetOther({type:this.form.type})
                    .then(res =>{
                        if(!res || !res.data) return false;
                        var data = res.data;
                        this.form.replyType = data.type;
                        this.form.wechat_text_id = data.vue.wechat_text_id;
                        this.form.wechat_image_id = data.vue.wechat_image_id;
                        this.form.wechat_mpnews_id = data.vue.wechat_mpnews_id;
                        var reply = {
                        	replyType : data.type,
                        	wechat_text_id : data.vue.wechat_text_id,
                        	wechat_image_id : data.vue.wechat_image_id,
                        	wechat_mpnews_id : data.vue.wechat_mpnews_id,
                        };
                        this.$refs.reply.setChoise(reply);
                    })
			},
			resetReply(){
                this.form.replyType = '';
                this.form.wechat_text_id = 0;
                this.form.wechat_image_id = 0;
                this.form.wechat_mpnews_id = 0;
            },
			getChoiseReply(reply){
				this.resetReply();
                this.form.replyType = reply.replyType;
                this.form.wechat_text_id = reply.wechat_text_id;
                this.form.wechat_image_id = reply.wechat_image_id;
                this.form.wechat_mpnews_id = reply.wechat_mpnews_id;
			},
			save(){
				if(this.form.replyType==''){
					this.$Message.error('请选择回复内容项');return false;
				}
				this.Axios.Wechat.Function.Reply.UpdateOther(this.form)
                    .then(res =>{
                        if(!res) return false;
                        
                    })
			}
		}
	}
</script>